#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct ColorStruct
{
    int r;
    int g;
    int b;
}CS;

CS targetset[16];

int getDist(CS* cs1, CS* cs2)
{
    return sqrt(pow(abs(cs1->r - cs2->r), 2)
            + pow(abs(cs1->g - cs2->g), 2) + pow(abs(cs1->b - cs2->b), 2));
}

void process(CS* cs, CS* out)
{
    int i = 0;
    int smallDist = pow(255, 2) * 3 + 1, distCur = 0;

    for(i = 0; i < 16; i++)
    {
        distCur = getDist(cs, &targetset[i]);

        if(smallDist > distCur)
        {
            smallDist = distCur;
            out->r = targetset[i].r;
            out->g = targetset[i].g;
            out->b = targetset[i].b;
        }
    }
    return ;

}
int main()
{
    int i = 0;
    CS cs, smallCS;


//    freopen("bin\\debug\\in.txt", "r", stdin);
//    freopen("bin\\debug\\out.txt", "w", stdout);

    for(i = 0; i < 16; i++)
    {
        scanf("%d %d %d", &targetset[i].r, &targetset[i].g, &targetset[i].b);
    }

    scanf("%d %d %d", &cs.r, &cs.g, &cs.b);


    while(cs.r != -1 && cs.g != -1 && cs.b != -1)
    {
        process(&cs, &smallCS);
        printf("(%d,%d,%d) maps to (%d,%d,%d)\n", cs.r, cs.g, cs.b, smallCS.r, smallCS.g, smallCS.b);
        scanf("%d %d %d", &cs.r, &cs.g, &cs.b);
    }
    return 0;
}
